package com.yq.front.service.impl;

import com.yq.api.comm.ResultHandle;
import com.yq.api.dto.UserTO;
import com.yq.front.service.LoginFrontService;
import com.yq.api.service.LoginServiceFacade;
import com.yq.front.util.UserVOUtil;
import com.yq.front.vo.UserVO;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * Created by yq on 16-7-30.
 */
@Service("loginFrontService")
public class LoginFrontServiceImpl implements LoginFrontService {
    private static final Log log = LogFactory.getLog(LoginFrontServiceImpl.class);
    @Resource(name = "loginServiceFacade")
    protected LoginServiceFacade LoginServiceFacade;
    public ResultHandle doLogin(UserVO userVO) {

        try {
            UserTO userTO = UserVOUtil.toUserTO(userVO);
            ResultHandle authenticateResult = LoginServiceFacade.authenticateUser(userTO);
            if(authenticateResult.getSuccess() != null && authenticateResult.getSuccess()){
                UserVOUtil.writeBack(userTO, userVO);
            }
            return authenticateResult;
        } catch (Exception e) {
            log.error(e);
            ResultHandle resultHandle = new ResultHandle();;
            resultHandle.setMessage(e.getMessage());
            return resultHandle;
        }
    }
}
